package com.molichuxing.services.sdk.alipay;

import java.util.Map;

import com.molichuxing.framework.utils.PropertiesUtil;

public class AlipayConfig {

	// 合作身份者ID，签约账号，以2088开头由16位纯数字组成的字符串，查看地址：https://b.alipay.com/order/pidAndKey.htm
	private String partner;

	// 收款支付宝账号，以2088开头由16位纯数字组成的字符串，一般情况下收款账号就是签约账号
	private String sellerId;

	// 商户appid
	private String appId;

	// 商户的私钥,需要PKCS8格式，RSA公私钥生成：https://doc.open.alipay.com/doc2/detail.htm?spm=a219a.7629140.0.0.nBDxfy&treeId=58&articleId=103242&docType=1
	private String privateKey;

	// 支付宝的公钥,查看地址：https://b.alipay.com/order/pidAndKey.htm
	private String publicKey;

	// 服务器异步通知页面路径 需http://或者https://格式的完整路径，不能加?id=123这类自定义参数，必须外网可以正常访问
	private String notifyUrl;

	// 页面跳转同步通知页面路径
	// 需http://或者https://格式的完整路径，不能加?id=123这类自定义参数，必须外网可以正常访问(商户可以自定义同步跳转地址)
	private String returnUrl;

	// 正式请求网关地址
	private String gatewayUrl = "https://openapi.alipay.com/gateway.do";

	// 沙箱请求网关地址
	private String sandboxGatewayUrl = "https://openapi.alipaydev.com/gateway.do";

	// 编码
	private String charset = "UTF-8";

	// 返回格式
	private String format = "json";

	// 支付类型 ，无需修改
	private String paymentType = "1";

	// 签名方式RSA2
	private String signType = "RSA2";

	private String productCode = "QUICK_MSECURITY_PAY";

	// 在这里配置防钓鱼信息，如果没开通防钓鱼功能，为空即可
	// 防钓鱼时间戳 若要使用请调用类文件submit中的query_timestamp函数
	// private String anti_phishing_key;

	// 客户端的IP地址 非局域网的外网IP地址，如：221.0.0.1
	// private String exter_invoke_ip;
	
	private static AlipayConfig instance;

	public static AlipayConfig getInstance() throws Exception {
		if (instance == null) {
			synchronized (AlipayConfig.class) {
				if (instance == null) {
					Map<String, String> properties = PropertiesUtil.getInstance().getAllProperties("config.properties");
					instance = new AlipayConfig(properties.get("alipay.partner"), properties.get("alipay.seller.id"),
							properties.get("alipay.app.id"), properties.get("alipay.private.key"),
							properties.get("alipay.public.key"), properties.get("alipay.notifyUrl"), null);
				}
			}
		}
		return instance;
	}
	

	private AlipayConfig(String partner, String sellerId, String appId, String privateKey, String publicKey,
			String notifyUrl, String returnUrl) {
		this.partner = partner;
		this.sellerId = sellerId;
		this.appId = appId;
		this.privateKey = privateKey;
		this.publicKey = publicKey;
		this.notifyUrl = notifyUrl;
		this.returnUrl = returnUrl;
	 }

	public String getPartner() {
		return partner;
	}

	public void setPartner(String partner) {
		this.partner = partner;
	}

	public String getSellerId() {
		return sellerId;
	}

	public void setSellerId(String sellerId) {
		this.sellerId = sellerId;
	}

	public String getAppId() {
		return appId;
	}

	public void setAppId(String appId) {
		this.appId = appId;
	}

	public String getPrivateKey() {
		return privateKey;
	}

	public void setPrivateKey(String privateKey) {
		this.privateKey = privateKey;
	}

	public String getPublicKey() {
		return publicKey;
	}

	public void setPublicKey(String publicKey) {
		this.publicKey = publicKey;
	}

	public String getNotifyUrl() {
		return notifyUrl;
	}

	public void setNotifyUrl(String notifyUrl) {
		this.notifyUrl = notifyUrl;
	}

	public String getReturnUrl() {
		return returnUrl;
	}

	public void setReturnUrl(String returnUrl) {
		this.returnUrl = returnUrl;
	}

	public String getGatewayUrl() {
		return gatewayUrl;
	}

	public void setGatewayUrl(String gatewayUrl) {
		this.gatewayUrl = gatewayUrl;
	}

	public String getSandboxGatewayUrl() {
		return sandboxGatewayUrl;
	}

	public void setSandboxGatewayUrl(String sandboxGatewayUrl) {
		this.sandboxGatewayUrl = sandboxGatewayUrl;
	}

	public String getCharset() {
		return charset;
	}

	public void setCharset(String charset) {
		this.charset = charset;
	}

	public String getFormat() {
		return format;
	}

	public void setFormat(String format) {
		this.format = format;
	}

	public String getPaymentType() {
		return paymentType;
	}

	public void setPaymentType(String paymentType) {
		this.paymentType = paymentType;
	}

	public String getSignType() {
		return signType;
	}

	public void setSignType(String signType) {
		this.signType = signType;
	}


	public String getProductCode() {
		return productCode;
	}


	public void setProductCode(String productCode) {
		this.productCode = productCode;
	}

}
